﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using PdfLib;

namespace Workflows.Components.TextMining.TextScraping
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class BoxedContentFilter:ContentFilterBase
    {
        

        #region Overrides of ContentFilterBase
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        public BoxedContentFilter(Guid id) : base(id)
        {
        }

        public override event ContentFiltered OnContentFiltered;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="srcContent"></param>
        public override void Filter(object srcContent)
        {
            Debug.Assert(srcContent !=null && srcContent.GetType()==typeof(BoxedContentProvider));

            BoxedContentProvider provider = (BoxedContentProvider) srcContent;
            string content =
                PdfTextReader.ReadBoxedContent(
                    provider.PdfFilePath, 
                    provider.PageNumber, 
                    provider.MinRectWidth,
                    provider.MinRectHeight);

            if (this.OnContentFiltered != null)
                this.OnContentFiltered(this.FilterID, content);
        }

        #endregion
    }
}
